<template>
	<view class="container">
		<u--form>
			<u-form-item label="箱码" prop="containerCode" labelWidth="120rpx">
				<u--input
					placeholder="请输入箱码"
					v-model.number="query.containerCode"
					suffixIcon="scan"
					suffixIconStyle="font-size: 68rpx"
					style="flex: 1;"
				>
				</u--input>
			</u-form-item>
		</u--form>
		<u-toast ref="uToast"></u-toast>
		<view class="commonButton">
			<u-button type="primary" :disabled="!query.containerCode" @click="confirmManual">确认</u-button>
		</view>
	</view>
</template>

<script>
	import { confirmManualAPI } from '@/api/work/outbound.js'
	export default {
		data() {
			return {
				query: {
					containerCode: ''
				}
			};
		},
		onLoad() {
			uni.$on('scancodedate',(data) => this.getCode(data.code))
		},  
		onUnload() {    
			uni.$off('scancodedate')
		},
		methods: {
			async getCode(code) {
				const regex = /^R-\d+$/
				if (regex.test(code)) {
					this.query.containerCode = code
				} else {
					return this.$refs.uToast.show({
						type: 'warning',
						message: '请扫描正确的箱码'
					})
				}
			},
			async confirmManual() {
				const submitForm = {
					containerCode: this.query.containerCode
				}
				const res = await confirmManualAPI(submitForm)
				if (res.code === 200) {
					this.query.containerCode = ''
					this.$refs.uToast.show({
						type: 'success',
						message: res.message
					})
				} else {
					return this.$refs.uToast.show({
						type: 'warning',
						message: res.message
					})
				}
			}
		}
	}
</script>

<style lang="scss">
</style>
